document.querySelector("#btn-login").addEventListener("click",async ()=>{
    // axios({
    //     url:"/register",
    //     method:"post",
    //     data:{
    //         username:"jack",
    //         password:"123456"
    //     }
    // })

    // 搜集数据
    const form = document.querySelector(".login-form")
    const data = serialize(form,{hash:true,empty:true})
    console.log(data);
    const { username, password } = data
    // 非空校验
    if(username === '' || password === ''){
        showToast("空着呢！！")
        return
    }  
    //长度校验
    if(username.length < 3 || username.length >30 || password.length <3 || password.length >30){
        showToast("长度不符合！！")
        return 
    }
    //数据提交
    // try{
        const res =  await axios.post("/login",{username,password})
        // console.log(res);
        showToast(res.message)
        localStorage.setItem("username",res.data.username)
        localStorage.setItem("token",res.data.token)
        console.log(res.data.data);
         setTimeout(() => {
            window.location.href = "./index.html"
         }, 1500)
    // }catch(error){
    //     showToast(error.response.data.message)
    // }
   
})

